using System;
using System.Diagnostics;
using System.Globalization;

namespace Atomic.Libraries.Physics.Units
{
	[Serializable]
	[DebuggerDisplay("{DebuggerDisplay}")]
	public class NitridingPotential
	{
		private double value;

		public NitridingPotential(double value)
		{
			this.value = value;
		}

		public static NitridingPotential FromUnit(IUnitSystem system, double value)
		{
			if (system.EnergyScaling == 1.0 && system.LengthScaling == 1.0)
			{
				return new NitridingPotential(value);
			}
			else
			{
				return new NitridingPotential(value / Math.Pow(system.EnergyScaling / (system.LengthScaling * system.LengthScaling * system.LengthScaling), -0.5));
			}
		}

		public static NitridingPotential FromInverseElectronVoltPerCubicAngstromRoot(double value)
		{
			return FromUnit(UnitSystem.AtomicSystem, value);
		}
		
		public static NitridingPotential FromInversePascalRoot(double value)
		{
			return FromUnit(UnitSystem.InternationalSystem, value);
		}

		public static NitridingPotential FromInverseBarRoot(double value)
		{
			return FromUnit(UnitSystem.InternationalSystem, value * Math.Pow(1.0e5, -0.5));
		}

		public double ToUnit(IUnitSystem system)
		{
			if (system.EnergyScaling == 1.0 && system.LengthScaling == 1.0)
			{
				return value;
			}
			else
			{
				return value * Math.Pow(system.EnergyScaling / (system.LengthScaling * system.LengthScaling * system.LengthScaling), -0.5);
			}
		}

		public double ToInverseElectronVoltPerCubicAngstromRoot()
		{
			return ToUnit(UnitSystem.AtomicSystem);
		}

		public double ToInversePascalRoot()
		{
			return ToUnit(UnitSystem.InternationalSystem);
		}

		public double ToInverseBarRoot()
		{
			return ToInversePascalRoot() * Math.Pow(1.0e-5, -0.5);
		}

		public static implicit operator double(NitridingPotential value)
		{
			return value.ToUnit(UnitSystem.AtomicSystem);
		}

		public static implicit operator NitridingPotential(double value)
		{
			return FromUnit(UnitSystem.AtomicSystem, value);
		}

		private string DebuggerDisplay
		{
			get
			{
				return string.Format(CultureInfo.InvariantCulture, "{0} (eV/Å^3)^-0.5 = {1} Pa^-0.5 = {2} bar^-0.5", ToInverseElectronVoltPerCubicAngstromRoot(), ToInversePascalRoot(), ToInverseBarRoot());
			}
		}
	}
}
